package mypack.openworld;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Base64;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;


public class Sight extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sight);
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("id", String.valueOf(1));
        String data = new Gson().toJson(hashMap);
        ServerInteraction serverInteraction = new ServerInteraction(new ServerResponseProcessor() {
            @Override
            public void process(String string) {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap = new Gson().fromJson(string, hashMap.getClass());
                byte[] image = Base64.decode(hashMap.get("photo"), Base64.NO_WRAP);
                    ((TextView) findViewById(R.id.description)).setText(hashMap.get("description"));
                Bitmap bitmapFactory = BitmapFactory.decodeByteArray(image, 0, image.length);
                ImageView imageView = (ImageView) findViewById(R.id.image);
                imageView.setImageBitmap(bitmapFactory);
            //    imageView.setMaxHeight(bitmapFactory.getHeight());
            //    imageView.setMaxWidth(bitmapFactory.getWidth());
            }
        });
        serverInteraction.execute("/sight_details.php", data);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sight, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
